using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeLegendCell_LegendCell"), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class LegendCell : ChartNamedElement, IChartMapArea
	{
		private ContentAlignment _alignment;
		private Color _backColor;
		private Size _cachedCellSize;
		private int _cachedCellSizeFontReducedBy;
		private int _cellSpan;
		private LegendCellType _cellType;
		private System.Drawing.Font _font;
		private FontCache _fontCache;
		private Color _foreColor;
		private string _image;
		private Size _imageSize;
		private Color _imageTransparentColor;
		private string _mapAreaAttribute;
		private Margins _margins;
		private string _postbackValue;
		private int _rowIndex;
		private Size _seriesSymbolSize;
		private string _text;
		private string _toolTip;
		private string _url;
		internal Rectangle cellPosition;
		internal Rectangle cellPositionWithMargins;

		public LegendCell()
		{
			this._text = string.Empty;
			this._foreColor = Color.Empty;
			this._backColor = Color.Empty;
			this._fontCache = new FontCache();
			this._image = string.Empty;
			this._imageTransparentColor = Color.Empty;
			this._imageSize = Size.Empty;
			this._seriesSymbolSize = new Size(200, 70);
			this._alignment = ContentAlignment.MiddleCenter;
			this._cellSpan = 1;
			this._toolTip = string.Empty;
			this._margins = new Margins(0, 0, 15, 15);
			this._rowIndex = -1;
			this._url = string.Empty;
			this._mapAreaAttribute = string.Empty;
			this._postbackValue = string.Empty;
			this.cellPosition = Rectangle.Empty;
			this.cellPositionWithMargins = Rectangle.Empty;
			this._cachedCellSize = Size.Empty;
			this.Intitialize(LegendCellType.Text, string.Empty, ContentAlignment.MiddleCenter);
		}

		public LegendCell(string text)
		{
			this._text = string.Empty;
			this._foreColor = Color.Empty;
			this._backColor = Color.Empty;
			this._fontCache = new FontCache();
			this._image = string.Empty;
			this._imageTransparentColor = Color.Empty;
			this._imageSize = Size.Empty;
			this._seriesSymbolSize = new Size(200, 70);
			this._alignment = ContentAlignment.MiddleCenter;
			this._cellSpan = 1;
			this._toolTip = string.Empty;
			this._margins = new Margins(0, 0, 15, 15);
			this._rowIndex = -1;
			this._url = string.Empty;
			this._mapAreaAttribute = string.Empty;
			this._postbackValue = string.Empty;
			this.cellPosition = Rectangle.Empty;
			this.cellPositionWithMargins = Rectangle.Empty;
			this._cachedCellSize = Size.Empty;
			this.Intitialize(LegendCellType.Text, text, ContentAlignment.MiddleCenter);
		}

		public LegendCell(LegendCellType cellType, string text)
		{
			this._text = string.Empty;
			this._foreColor = Color.Empty;
			this._backColor = Color.Empty;
			this._fontCache = new FontCache();
			this._image = string.Empty;
			this._imageTransparentColor = Color.Empty;
			this._imageSize = Size.Empty;
			this._seriesSymbolSize = new Size(200, 70);
			this._alignment = ContentAlignment.MiddleCenter;
			this._cellSpan = 1;
			this._toolTip = string.Empty;
			this._margins = new Margins(0, 0, 15, 15);
			this._rowIndex = -1;
			this._url = string.Empty;
			this._mapAreaAttribute = string.Empty;
			this._postbackValue = string.Empty;
			this.cellPosition = Rectangle.Empty;
			this.cellPositionWithMargins = Rectangle.Empty;
			this._cachedCellSize = Size.Empty;
			this.Intitialize(cellType, text, ContentAlignment.MiddleCenter);
		}

		public LegendCell(LegendCellType cellType, string text, ContentAlignment alignment)
		{
			this._text = string.Empty;
			this._foreColor = Color.Empty;
			this._backColor = Color.Empty;
			this._fontCache = new FontCache();
			this._image = string.Empty;
			this._imageTransparentColor = Color.Empty;
			this._imageSize = Size.Empty;
			this._seriesSymbolSize = new Size(200, 70);
			this._alignment = ContentAlignment.MiddleCenter;
			this._cellSpan = 1;
			this._toolTip = string.Empty;
			this._margins = new Margins(0, 0, 15, 15);
			this._rowIndex = -1;
			this._url = string.Empty;
			this._mapAreaAttribute = string.Empty;
			this._postbackValue = string.Empty;
			this.cellPosition = Rectangle.Empty;
			this.cellPositionWithMargins = Rectangle.Empty;
			this._cachedCellSize = Size.Empty;
			this.Intitialize(cellType, text, alignment);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && (this._fontCache != null))
			{
				this._fontCache.Dispose();
				this._fontCache = null;
			}
			base.Dispose(disposing);
		}

		private Color GetCellBackColor()
		{
			Color backColor = this.BackColor;
			if (!this.BackColor.IsEmpty || (this.Legend == null))
			{
				return backColor;
			}
			if (this.LegendItem != null)
			{
				int index = this.LegendItem.Cells.IndexOf(this);
				if (((index >= 0) && (index < this.Legend.CellColumns.Count)) && !this.Legend.CellColumns[index].BackColor.IsEmpty)
				{
					backColor = this.Legend.CellColumns[index].BackColor;
				}
			}
			if ((!backColor.IsEmpty || !this.Legend.InterlacedRows) || ((this._rowIndex % 2) == 0))
			{
				return backColor;
			}
			if (this.Legend.InterlacedRowsColor.IsEmpty)
			{
				if (this.Legend.BackColor == Color.Empty)
				{
					return Color.LightGray;
				}
				if (this.Legend.BackColor == Color.Transparent)
				{
					if ((base.Chart.BackColor != Color.Transparent) && (base.Chart.BackColor != Color.Black))
					{
						return ChartGraphics.GetGradientColor(base.Chart.BackColor, Color.Black, 0.2);
					}
					return Color.LightGray;
				}
				return ChartGraphics.GetGradientColor(this.Legend.BackColor, Color.Black, 0.2);
			}
			return this.Legend.InterlacedRowsColor;
		}

		private System.Drawing.Font GetCellFont(System.Drawing.Font legendAutoFont, int fontSizeReducedBy, out bool disposeFont)
		{
			System.Drawing.Font font = this.Font;
			disposeFont = false;
			if ((font == null) && (this.Legend != null))
			{
				if (this.LegendItem != null)
				{
					int index = this.LegendItem.Cells.IndexOf(this);
					if (((index >= 0) && (index < this.Legend.CellColumns.Count)) && (this.Legend.CellColumns[index].Font != null))
					{
						font = this.Legend.CellColumns[index].Font;
					}
				}
				if (font == null)
				{
					return legendAutoFont;
				}
			}
			if ((font == null) || (fontSizeReducedBy == 0))
			{
				return font;
			}
			disposeFont = true;
			int num2 = (int)Math.Round((double)(font.Size - fontSizeReducedBy));
			if (num2 < 1)
			{
				num2 = 1;
			}
			return new System.Drawing.Font(font.FontFamily, (float)num2, font.Style, font.Unit);
		}

		private Color GetCellForeColor()
		{
			if (!this.ForeColor.IsEmpty)
			{
				return this.ForeColor;
			}
			if (this.Legend == null)
			{
				return Color.Black;
			}
			if (this.LegendItem != null)
			{
				int index = this.LegendItem.Cells.IndexOf(this);
				if (((index >= 0) && (index < this.Legend.CellColumns.Count)) && !this.Legend.CellColumns[index].ForeColor.IsEmpty)
				{
					return this.Legend.CellColumns[index].ForeColor;
				}
			}
			return this.Legend.ForeColor;
		}

		private string GetCellMapAreaAttributes()
		{
			if (this._mapAreaAttribute.Length > 0)
			{
				return this._mapAreaAttribute;
			}
			if (this.LegendItem != null)
			{
				return this.LegendItem.MapAreaAttributes;
			}
			return string.Empty;
		}

		private string GetCellPostBackValue()
		{
			if (this._postbackValue.Length > 0)
			{
				return this._postbackValue;
			}
			if (this.LegendItem != null)
			{
				return this.LegendItem.PostBackValue;
			}
			return string.Empty;
		}

		private string GetCellText()
		{
			string s = this.Text.Replace(@"\n", "\n");
			if (this.LegendItem != null)
			{
				s = s.Replace("#LEGENDTEXT", this.LegendItem.Name);
			}
			else
			{
				s = s.Replace("#LEGENDTEXT", "");
			}
			if (this.Legend != null)
			{
				int textWrapThreshold = this.Legend.TextWrapThreshold;
				if ((textWrapThreshold <= 0) || (s.Length <= textWrapThreshold))
				{
					return s;
				}
				int num2 = 0;
				for (int i = 0; i < s.Length; i++)
				{
					if (s[i] == '\n')
					{
						num2 = 0;
					}
					else
					{
						num2++;
						if (char.IsWhiteSpace(s, i) && (num2 >= textWrapThreshold))
						{
							num2 = 0;
							s = s.Substring(0, i) + "\n" + s.Substring(i + 1).TrimStart(new char[0]);
						}
					}
				}
			}
			return s;
		}

		private string GetCellToolTip()
		{
			if (this.ToolTip.Length > 0)
			{
				return this.ToolTip;
			}
			if (this.LegendItem != null)
			{
				return this.LegendItem.ToolTip;
			}
			return string.Empty;
		}

		private string GetCellUrl()
		{
			if (this._url.Length > 0)
			{
				return this._url;
			}
			if (this.LegendItem != null)
			{
				return this.LegendItem.Url;
			}
			return string.Empty;
		}

		private void Intitialize(LegendCellType cellType, string text, ContentAlignment alignment)
		{
			this._cellType = cellType;
			if (this._cellType == LegendCellType.Image)
			{
				this._image = text;
			}
			else
			{
				this._text = text;
			}
			this._alignment = alignment;
			this.PostBackValue = string.Empty;
		}

		internal Size MeasureCell(ChartGraphics graph, int fontSizeReducedBy, System.Drawing.Font legendAutoFont, Size singleWCharacterSize)
		{
			if ((this._cachedCellSizeFontReducedBy == fontSizeReducedBy) && !this._cachedCellSize.IsEmpty)
			{
				return this._cachedCellSize;
			}
			Size empty = Size.Empty;
			bool disposeFont = false;
			System.Drawing.Font font = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
			if (this.CellType == LegendCellType.SeriesSymbol)
			{
				empty.Width = (int)(((float)(Math.Abs(this.SeriesSymbolSize.Width) * singleWCharacterSize.Width)) / 100f);
				empty.Height = (int)(((float)(Math.Abs(this.SeriesSymbolSize.Height) * singleWCharacterSize.Height)) / 100f);
			}
			else if (this.CellType == LegendCellType.Image)
			{
				if (this.ImageSize.IsEmpty && (this.Image.Length > 0))
				{
					SizeF size = new SizeF();
					if (base.Common.ImageLoader.GetAdjustedImageSize(this.Image, graph.Graphics, ref size))
					{
						empty.Width = (int)size.Width;
						empty.Height = (int)size.Height;
					}
				}
				else
				{
					empty.Width = (int)(((float)(Math.Abs(this.ImageSize.Width) * singleWCharacterSize.Width)) / 100f);
					empty.Height = (int)(((float)(Math.Abs(this.ImageSize.Height) * singleWCharacterSize.Height)) / 100f);
				}
			}
			else
			{
				if (this.CellType != LegendCellType.Text)
				{
					throw new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString()));
				}
				empty = graph.MeasureStringAbs(this.GetCellText() + "I", font);
			}
			empty.Width += (int)(((float)((this.Margins.Left + this.Margins.Right) * singleWCharacterSize.Width)) / 100f);
			empty.Height += (int)(((float)((this.Margins.Top + this.Margins.Bottom) * singleWCharacterSize.Height)) / 100f);
			if ((this.LegendItem != null) && (this.LegendItem.SeparatorType != LegendSeparatorStyle.None))
			{
				empty.Height += this.Legend.GetSeparatorSize(this.LegendItem.SeparatorType).Height;
			}
			if (disposeFont)
			{
				font.Dispose();
				font = null;
			}
			this._cachedCellSize = empty;
			this._cachedCellSizeFontReducedBy = fontSizeReducedBy;
			return empty;
		}

		internal void Paint(ChartGraphics chartGraph, int fontSizeReducedBy, System.Drawing.Font legendAutoFont, Size singleWCharacterSize)
		{
			if ((this.cellPosition.Width > 0) && (this.cellPosition.Height > 0))
			{
				if (base.Common.ProcessModePaint)
				{
					Color cellBackColor = this.GetCellBackColor();
					RectangleF relativeRectangle = chartGraph.GetRelativeRectangle(this.cellPositionWithMargins);
					if (!cellBackColor.IsEmpty)
					{
						chartGraph.FillRectangleRel(relativeRectangle, cellBackColor, ChartHatchStyle.None, string.Empty, ChartImageWrapMode.Tile, Color.Empty, ChartImageAlignmentStyle.Center, GradientStyle.None, Color.Empty, Color.Empty, 0, ChartDashStyle.NotSet, Color.Empty, 0, PenAlignment.Inset);
					}
					base.Chart.CallOnPrePaint(new ChartPaintEventArgs(this, chartGraph, base.Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height)));
					switch (this.CellType)
					{
						case LegendCellType.Text:
							this.PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont);
							break;

						case LegendCellType.SeriesSymbol:
							this.PaintCellSeriesSymbol(chartGraph, (SizeF)singleWCharacterSize);
							break;

						case LegendCellType.Image:
							this.PaintCellImage(chartGraph, singleWCharacterSize);
							break;

						default:
							throw new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString()));
					}
					base.Chart.CallOnPostPaint(new ChartPaintEventArgs(this, chartGraph, base.Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height)));
				}
				if (base.Common.ProcessModeRegions)
				{
					base.Common.HotRegionsList.AddHotRegion(chartGraph.GetRelativeRectangle(this.cellPositionWithMargins), this.GetCellToolTip(), this.GetCellUrl(), this.GetCellMapAreaAttributes(), this.GetCellPostBackValue(), this.LegendItem, this, ChartElementType.LegendItem, this.LegendItem.SeriesName);
				}
			}
		}

		private void PaintCellImage(ChartGraphics chartGraph, Size singleWCharacterSize)
		{
			if (this.Image.Length > 0)
			{
				Rectangle empty = Rectangle.Empty;
				System.Drawing.Image image = base.Common.ImageLoader.LoadImage(this.Image);
				SizeF size = new SizeF();
				ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref size);
				empty.Width = (int)size.Width;
				empty.Height = (int)size.Height;
				Rectangle cellPosition = this.cellPosition;
				cellPosition.Width = empty.Width;
				cellPosition.Height = empty.Height;
				if (!this.ImageSize.IsEmpty)
				{
					if (this.ImageSize.Width > 0)
					{
						int width = (int)(((float)(this.ImageSize.Width * singleWCharacterSize.Width)) / 100f);
						if (width > this.cellPosition.Width)
						{
							width = this.cellPosition.Width;
						}
						cellPosition.Width = width;
					}
					if (this.ImageSize.Height > 0)
					{
						int height = (int)(((float)(this.ImageSize.Height * singleWCharacterSize.Height)) / 100f);
						if (height > this.cellPosition.Height)
						{
							height = this.cellPosition.Height;
						}
						cellPosition.Height = height;
					}
				}
				float num3 = 1f;
				if (empty.Height > cellPosition.Height)
				{
					num3 = ((float)empty.Height) / ((float)cellPosition.Height);
				}
				if (empty.Width > cellPosition.Width)
				{
					num3 = Math.Max(num3, ((float)empty.Width) / ((float)cellPosition.Width));
				}
				empty.Height = (int)(((float)empty.Height) / num3);
				empty.Width = (int)(((float)empty.Width) / num3);
				empty.X = (int)((this.cellPosition.X + (((float)this.cellPosition.Width) / 2f)) - (((float)empty.Width) / 2f));
				empty.Y = (int)((this.cellPosition.Y + (((float)this.cellPosition.Height) / 2f)) - (((float)empty.Height) / 2f));
				if (((this.Alignment == ContentAlignment.BottomLeft) || (this.Alignment == ContentAlignment.MiddleLeft)) || (this.Alignment == ContentAlignment.TopLeft))
				{
					empty.X = this.cellPosition.X;
				}
				else if (((this.Alignment == ContentAlignment.BottomRight) || (this.Alignment == ContentAlignment.MiddleRight)) || (this.Alignment == ContentAlignment.TopRight))
				{
					empty.X = this.cellPosition.Right - empty.Width;
				}
				if (((this.Alignment == ContentAlignment.BottomCenter) || (this.Alignment == ContentAlignment.BottomLeft)) || (this.Alignment == ContentAlignment.BottomRight))
				{
					empty.Y = this.cellPosition.Bottom - empty.Height;
				}
				else if (((this.Alignment == ContentAlignment.TopCenter) || (this.Alignment == ContentAlignment.TopLeft)) || (this.Alignment == ContentAlignment.TopRight))
				{
					empty.Y = this.cellPosition.Y;
				}
				ImageAttributes imageAttr = new ImageAttributes();
				if (this.ImageTransparentColor != Color.Empty)
				{
					imageAttr.SetColorKey(this.ImageTransparentColor, this.ImageTransparentColor, ColorAdjustType.Default);
				}
				SmoothingMode smoothingMode = chartGraph.SmoothingMode;
				CompositingQuality compositingQuality = chartGraph.Graphics.CompositingQuality;
				InterpolationMode interpolationMode = chartGraph.Graphics.InterpolationMode;
				chartGraph.SmoothingMode = SmoothingMode.AntiAlias;
				chartGraph.Graphics.CompositingQuality = CompositingQuality.HighQuality;
				chartGraph.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
				chartGraph.DrawImage(image, empty, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
				chartGraph.SmoothingMode = smoothingMode;
				chartGraph.Graphics.CompositingQuality = compositingQuality;
				chartGraph.Graphics.InterpolationMode = interpolationMode;
			}
		}

		private void PaintCellSeriesSymbol(ChartGraphics chartGraph, SizeF singleWCharacterSize)
		{
			LegendItem legendItem = this.LegendItem;
			Rectangle cellPosition = this.cellPosition;
			if (this.SeriesSymbolSize.Width >= 0)
			{
				int width = (int)((this.SeriesSymbolSize.Width * singleWCharacterSize.Width) / 100f);
				if (width > this.cellPosition.Width)
				{
					width = this.cellPosition.Width;
				}
				cellPosition.Width = width;
			}
			if (this.SeriesSymbolSize.Height >= 0)
			{
				int height = (int)((this.SeriesSymbolSize.Height * singleWCharacterSize.Height) / 100f);
				if (height > this.cellPosition.Height)
				{
					height = this.cellPosition.Height;
				}
				cellPosition.Height = height;
			}
			if ((cellPosition.Height > 0) && (cellPosition.Width > 0))
			{
				cellPosition.X = (int)((this.cellPosition.X + (((float)this.cellPosition.Width) / 2f)) - (((float)cellPosition.Width) / 2f));
				cellPosition.Y = (int)((this.cellPosition.Y + (((float)this.cellPosition.Height) / 2f)) - (((float)cellPosition.Height) / 2f));
				if (((this.Alignment == ContentAlignment.BottomLeft) || (this.Alignment == ContentAlignment.MiddleLeft)) || (this.Alignment == ContentAlignment.TopLeft))
				{
					cellPosition.X = this.cellPosition.X;
				}
				else if (((this.Alignment == ContentAlignment.BottomRight) || (this.Alignment == ContentAlignment.MiddleRight)) || (this.Alignment == ContentAlignment.TopRight))
				{
					cellPosition.X = this.cellPosition.Right - cellPosition.Width;
				}
				if (((this.Alignment == ContentAlignment.BottomCenter) || (this.Alignment == ContentAlignment.BottomLeft)) || (this.Alignment == ContentAlignment.BottomRight))
				{
					cellPosition.Y = this.cellPosition.Bottom - cellPosition.Height;
				}
				else if (((this.Alignment == ContentAlignment.TopCenter) || (this.Alignment == ContentAlignment.TopLeft)) || (this.Alignment == ContentAlignment.TopRight))
				{
					cellPosition.Y = this.cellPosition.Y;
				}
				chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
				if (legendItem.Image.Length > 0)
				{
					Rectangle empty = Rectangle.Empty;
					System.Drawing.Image image = base.Common.ImageLoader.LoadImage(legendItem.Image);
					if (image != null)
					{
						SizeF size = new SizeF();
						ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref size);
						empty.Width = (int)size.Width;
						empty.Height = (int)size.Height;
						float num3 = 1f;
						if (empty.Height > cellPosition.Height)
						{
							num3 = ((float)empty.Height) / ((float)cellPosition.Height);
						}
						if (empty.Width > cellPosition.Width)
						{
							num3 = Math.Max(num3, ((float)empty.Width) / ((float)cellPosition.Width));
						}
						empty.Height = (int)(((float)empty.Height) / num3);
						empty.Width = (int)(((float)empty.Width) / num3);
						empty.X = (int)((cellPosition.X + (((float)cellPosition.Width) / 2f)) - (((float)empty.Width) / 2f));
						empty.Y = (int)((cellPosition.Y + (((float)cellPosition.Height) / 2f)) - (((float)empty.Height) / 2f));
						ImageAttributes imageAttr = new ImageAttributes();
						if (legendItem.BackImageTransparentColor != Color.Empty)
						{
							imageAttr.SetColorKey(legendItem.BackImageTransparentColor, legendItem.BackImageTransparentColor, ColorAdjustType.Default);
						}
						chartGraph.DrawImage(image, empty, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
					}
				}
				else
				{
					int num4 = (int)Math.Round((double)((3f * chartGraph.Graphics.DpiX) / 96f));
					int num5 = (int)Math.Round((double)((3f * chartGraph.Graphics.DpiX) / 96f));
					if (legendItem.ImageStyle == LegendImageStyle.Rectangle)
					{
						int num6 = (int)Math.Round((double)((2f * chartGraph.Graphics.DpiX) / 96f));
						chartGraph.FillRectangleRel(chartGraph.GetRelativeRectangle(cellPosition), legendItem.Color, legendItem.BackHatchStyle, legendItem.Image, legendItem.backImageWrapMode, legendItem.BackImageTransparentColor, legendItem.backImageAlign, legendItem.backGradientStyle, legendItem.backSecondaryColor, legendItem.borderColor, (legendItem.BorderWidth > num6) ? num6 : legendItem.BorderWidth, legendItem.BorderDashStyle, legendItem.ShadowColor, (legendItem.ShadowOffset > num4) ? num4 : legendItem.ShadowOffset, PenAlignment.Inset);
					}
					if (legendItem.ImageStyle == LegendImageStyle.Line)
					{
						Point point = new Point();
						point.X = cellPosition.X;
						point.Y = cellPosition.Y + ((int)(((float)cellPosition.Height) / 2f));
						Point point2 = new Point();
						point2.Y = point.Y;
						point2.X = cellPosition.Right;
						SmoothingMode smoothingMode = chartGraph.SmoothingMode;
						chartGraph.SmoothingMode = SmoothingMode.None;
						chartGraph.DrawLineRel(legendItem.Color, (legendItem.borderWidth > num5) ? num5 : legendItem.borderWidth, legendItem.borderDashStyle, chartGraph.GetRelativePoint((PointF)point), chartGraph.GetRelativePoint((PointF)point2), legendItem.shadowColor, (legendItem.shadowOffset > num4) ? num4 : legendItem.shadowOffset);
						chartGraph.SmoothingMode = smoothingMode;
					}
					if ((legendItem.ImageStyle == LegendImageStyle.Marker) || (legendItem.ImageStyle == LegendImageStyle.Line))
					{
						MarkerStyle markerStyle = legendItem.markerStyle;
						if (legendItem.style == LegendImageStyle.Marker)
						{
							markerStyle = (legendItem.markerStyle == MarkerStyle.None) ? MarkerStyle.Circle : legendItem.markerStyle;
						}
						if ((markerStyle != MarkerStyle.None) || (legendItem.markerImage.Length > 0))
						{
							int markerSize = Math.Min(cellPosition.Width, cellPosition.Height);
							markerSize = (int)Math.Min((float)legendItem.markerSize, (legendItem.style == LegendImageStyle.Line) ? (2f * (((float)markerSize) / 3f)) : ((float)markerSize));
							int markerBorderSize = (legendItem.MarkerBorderWidth > num5) ? num5 : legendItem.MarkerBorderWidth;
							if (markerBorderSize > 0)
							{
								markerSize -= markerBorderSize;
								if (markerSize < 1)
								{
									markerSize = 1;
								}
							}
							Point point3 = new Point();
							point3.X = cellPosition.X + ((int)(((float)cellPosition.Width) / 2f));
							point3.Y = cellPosition.Y + ((int)(((float)cellPosition.Height) / 2f));
							Rectangle imageScaleRect = Rectangle.Empty;
							if (legendItem.markerImage.Length > 0)
							{
								System.Drawing.Image image2 = base.Common.ImageLoader.LoadImage(legendItem.markerImage);
								SizeF ef2 = new SizeF();
								ImageLoader.GetAdjustedImageSize(image2, chartGraph.Graphics, ref ef2);
								imageScaleRect.Width = (int)ef2.Width;
								imageScaleRect.Height = (int)ef2.Height;
								float num9 = 1f;
								if (imageScaleRect.Height > cellPosition.Height)
								{
									num9 = ((float)imageScaleRect.Height) / ((float)cellPosition.Height);
								}
								if (imageScaleRect.Width > cellPosition.Width)
								{
									num9 = Math.Max(num9, ((float)imageScaleRect.Width) / ((float)cellPosition.Width));
								}
								imageScaleRect.Height = (int)(((float)imageScaleRect.Height) / num9);
								imageScaleRect.Width = (int)(((float)imageScaleRect.Width) / num9);
							}
							PointF tf = new PointF((float)point3.X, (float)point3.Y);
							if ((markerSize % 2) != 0.0)
							{
								tf.X -= 0.5f;
								tf.Y -= 0.5f;
							}
							chartGraph.DrawMarkerRel(chartGraph.GetRelativePoint(tf), markerStyle, markerSize, (legendItem.markerColor == Color.Empty) ? legendItem.Color : legendItem.markerColor, (legendItem.markerBorderColor == Color.Empty) ? legendItem.borderColor : legendItem.markerBorderColor, markerBorderSize, legendItem.markerImage, legendItem.markerImageTransparentColor, (legendItem.shadowOffset > num4) ? num4 : legendItem.shadowOffset, legendItem.shadowColor, imageScaleRect);
						}
					}
				}
				chartGraph.EndHotRegion();
			}
		}

		private void PaintCellText(ChartGraphics chartGraph, int fontSizeReducedBy, System.Drawing.Font legendAutoFont)
		{
			bool disposeFont = false;
			System.Drawing.Font font = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
			chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
			using (SolidBrush brush = new SolidBrush(this.GetCellForeColor()))
			{
				using (StringFormat format = new StringFormat(StringFormat.GenericDefault))
				{
					format.FormatFlags = StringFormatFlags.LineLimit;
					format.Trimming = StringTrimming.EllipsisCharacter;
					format.Alignment = StringAlignment.Center;
					if (((this.Alignment == ContentAlignment.BottomLeft) || (this.Alignment == ContentAlignment.MiddleLeft)) || (this.Alignment == ContentAlignment.TopLeft))
					{
						format.Alignment = StringAlignment.Near;
					}
					else if (((this.Alignment == ContentAlignment.BottomRight) || (this.Alignment == ContentAlignment.MiddleRight)) || (this.Alignment == ContentAlignment.TopRight))
					{
						format.Alignment = StringAlignment.Far;
					}
					format.LineAlignment = StringAlignment.Center;
					if (((this.Alignment == ContentAlignment.BottomCenter) || (this.Alignment == ContentAlignment.BottomLeft)) || (this.Alignment == ContentAlignment.BottomRight))
					{
						format.LineAlignment = StringAlignment.Far;
					}
					else if (((this.Alignment == ContentAlignment.TopCenter) || (this.Alignment == ContentAlignment.TopLeft)) || (this.Alignment == ContentAlignment.TopRight))
					{
						format.LineAlignment = StringAlignment.Near;
					}
					SizeF ef = (SizeF)chartGraph.MeasureStringAbs(this.GetCellText(), font, new SizeF(10000f, 10000f), format);
					if ((ef.Height > this.cellPosition.Height) && ((format.FormatFlags & StringFormatFlags.LineLimit) != 0))
					{
						format.FormatFlags ^= StringFormatFlags.LineLimit;
					}
					else if ((ef.Height < this.cellPosition.Height) && ((format.FormatFlags & StringFormatFlags.LineLimit) == 0))
					{
						format.FormatFlags |= StringFormatFlags.LineLimit;
					}
					chartGraph.DrawStringRel(this.GetCellText(), font, brush, chartGraph.GetRelativeRectangle(this.cellPosition), format);
				}
			}
			chartGraph.EndHotRegion();
			if (disposeFont)
			{
				font.Dispose();
				font = null;
			}
		}

		internal void ResetCache()
		{
			this._cachedCellSize = Size.Empty;
			this._cachedCellSizeFontReducedBy = 0;
		}

		internal void SetCellPosition(int rowIndex, Rectangle position, Size singleWCharacterSize)
		{
			this.cellPosition = position;
			this.cellPositionWithMargins = position;
			this._rowIndex = rowIndex;
			this.cellPosition.X += (int)(((float)(this.Margins.Left * singleWCharacterSize.Width)) / 100f);
			this.cellPosition.Y += (int)(((float)(this.Margins.Top * singleWCharacterSize.Height)) / 100f);
			this.cellPosition.Width -= ((int)(((float)(this.Margins.Left * singleWCharacterSize.Width)) / 100f)) + ((int)(((float)(this.Margins.Right * singleWCharacterSize.Width)) / 100f));
			this.cellPosition.Height -= ((int)(((float)(this.Margins.Top * singleWCharacterSize.Height)) / 100f)) + ((int)(((float)(this.Margins.Bottom * singleWCharacterSize.Height)) / 100f));
			if ((this.LegendItem != null) && (this.LegendItem.SeparatorType != LegendSeparatorStyle.None))
			{
				this.cellPosition.Height -= this.Legend.GetSeparatorSize(this.LegendItem.SeparatorType).Height;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		internal bool ShouldSerializeMargins()
		{
			if (((this._margins.Top == 0) && (this._margins.Bottom == 0)) && ((this._margins.Left == 15) && (this._margins.Right == 15)))
			{
				return false;
			}
			return true;
		}

		[SRCategory("CategoryAttributeLayout"), DefaultValue(0x20), SRDescription("DescriptionAttributeLegendCell_Alignment")]
		public virtual ContentAlignment Alignment
		{
			get
			{
				return this._alignment;
			}
			set
			{
				this._alignment = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeAppearance"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributeBackColor"), DefaultValue(typeof(Color), ""), TypeConverter(typeof(ColorConverter))]
		public virtual Color BackColor
		{
			get
			{
				return this._backColor;
			}
			set
			{
				this._backColor = value;
				this.Invalidate();
			}
		}

		[DefaultValue(1), SRCategory("CategoryAttributeLayout"), SRDescription("DescriptionAttributeLegendCell_CellSpan")]
		public virtual int CellSpan
		{
			get
			{
				return this._cellSpan;
			}
			set
			{
				if (value < 1)
				{
					throw new ArgumentException(SR.ExceptionLegendCellSpanIsLessThenOne, "value");
				}
				this._cellSpan = value;
				this.Invalidate();
			}
		}

		[ParenthesizePropertyName(true), DefaultValue(0), SRDescription("DescriptionAttributeLegendCell_CellType"), SRCategory("CategoryAttributeAppearance")]
		public virtual LegendCellType CellType
		{
			get
			{
				return this._cellType;
			}
			set
			{
				this._cellType = value;
				this.Invalidate();
			}
		}

		[DefaultValue((string)null), SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeLegendCell_Font")]
		public virtual System.Drawing.Font Font
		{
			get
			{
				return this._font;
			}
			set
			{
				this._font = value;
				this.Invalidate();
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributeForeColor"), TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(Color), "")]
		public virtual Color ForeColor
		{
			get
			{
				return this._foreColor;
			}
			set
			{
				this._foreColor = value;
				this.Invalidate();
			}
		}

		[Editor(typeof(ImageValueEditor), typeof(UITypeEditor)), DefaultValue(""), SRDescription("DescriptionAttributeLegendCell_Image"), SRCategory("CategoryAttributeAppearance")]
		public virtual string Image
		{
			get
			{
				return this._image;
			}
			set
			{
				this._image = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(Size), "0, 0"), SRCategory("CategoryAttributeLayout"), TypeConverter(typeof(SizeEmptyValueConverter)), SRDescription("DescriptionAttributeLegendCell_ImageSize")]
		public virtual Size ImageSize
		{
			get
			{
				return this._imageSize;
			}
			set
			{
				if ((value.Width < 0) || (value.Height < 0))
				{
					throw new ArgumentException(SR.ExceptionLegendCellImageSizeIsNegative, "value");
				}
				this._imageSize = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(Color), ""), SRDescription("DescriptionAttributeImageTransparentColor"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance")]
		public virtual Color ImageTransparentColor
		{
			get
			{
				return this._imageTransparentColor;
			}
			set
			{
				this._imageTransparentColor = value;
				this.Invalidate();
			}
		}

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), SerializationVisibility(SerializationVisibility.Hidden)]
		public virtual Legend Legend
		{
			get
			{
				LegendItem legendItem = this.LegendItem;
				if (legendItem != null)
				{
					return legendItem.Legend;
				}
				return null;
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden)]
		public virtual LegendItem LegendItem
		{
			get
			{
				if (this.Parent != null)
				{
					return (this.Parent.Parent as LegendItem);
				}
				return null;
			}
		}

		[DefaultValue(""), SRCategory("CategoryAttributeMapArea"), SRDescription("DescriptionAttributeMapAreaAttributes")]
		public virtual string MapAreaAttributes
		{
			get
			{
				return this._mapAreaAttribute;
			}
			set
			{
				this._mapAreaAttribute = value;
			}
		}

		[PersistenceMode(PersistenceMode.InnerProperty), SRCategory("CategoryAttributeLayout"), DefaultValue(typeof(Margins), "0,0,15,15"), SRDescription("DescriptionAttributeLegendCell_Margins"), SerializationVisibility(SerializationVisibility.Attribute), NotifyParentProperty(true)]
		public virtual Margins Margins
		{
			get
			{
				return this._margins;
			}
			set
			{
				this._margins = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeMisc"), SRDescription("DescriptionAttributeLegendCell_Name")]
		public override string Name
		{
			get
			{
				return base.Name;
			}
			set
			{
				base.Name = value;
			}
		}

		[DefaultValue(""), SRDescription("DescriptionAttributePostBackValue"), SRCategory("CategoryAttributeMapArea")]
		public string PostBackValue
		{
			get
			{
				return this._postbackValue;
			}
			set
			{
				this._postbackValue = value;
			}
		}

		[DefaultValue(typeof(Size), "200, 70"), SRCategory("CategoryAttributeLayout"), SRDescription("DescriptionAttributeLegendCell_SeriesSymbolSize")]
		public virtual Size SeriesSymbolSize
		{
			get
			{
				return this._seriesSymbolSize;
			}
			set
			{
				if ((value.Width < 0) || (value.Height < 0))
				{
					throw new ArgumentException(SR.ExceptionLegendCellSeriesSymbolSizeIsNegative, "value");
				}
				this._seriesSymbolSize = value;
				this.Invalidate();
			}
		}

		[DefaultValue(""), SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeLegendCell_Text")]
		public virtual string Text
		{
			get
			{
				return this._text;
			}
			set
			{
				this._text = value;
				this.Invalidate();
			}
		}

		[DefaultValue(""), SRCategory("CategoryAttributeMapArea"), SRDescription("DescriptionAttributeToolTip")]
		public virtual string ToolTip
		{
			get
			{
				return this._toolTip;
			}
			set
			{
				this._toolTip = value;
			}
		}

		[SRDescription("DescriptionAttributeUrl"), DefaultValue(""), Editor(typeof(UrlValueEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeMapArea")]
		public virtual string Url
		{
			get
			{
				return this._url;
			}
			set
			{
				this._url = value;
			}
		}
	}
}

